package com.store.util;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * 分页结果集
 */
public class PageInfo<T> implements Serializable {

    /** 当前页 */
    private int pageNum;

    /** 每页的数量 */
    private int pageSize;

    /** 当前页的数量 */
    private int size;

    /** 总记录数 */
    private long total;

    /** 总页数 */
    private int pages;

    /**结果集(每页显示的数据) */
    private List<T> list;

    /** 是否为第一页 */
    private boolean isFirstPage = false;

    /** 是否为最后一页 */
    private boolean isLastPage = false;

    /** 是否有前一页 */
    private boolean hasPreviousPage = false;

    /** 是否有下一页 */
    private boolean hasNextPage = false;

    public PageInfo() {
    }

    public PageInfo(int pageNum, int pageSize, int size, long total, int pages, List<T> list, boolean isFirstPage, boolean isLastPage, boolean hasPreviousPage, boolean hasNextPage) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.size = size;
        this.total = total;
        this.pages = pages;
        this.list = list;
        this.isFirstPage = isFirstPage;
        this.isLastPage = isLastPage;
        this.hasPreviousPage = hasPreviousPage;
        this.hasNextPage = hasNextPage;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public boolean isFirstPage() {
        return isFirstPage;
    }

    public void setFirstPage(boolean firstPage) {
        isFirstPage = firstPage;
    }

    public boolean isLastPage() {
        return isLastPage;
    }

    public void setLastPage(boolean lastPage) {
        isLastPage = lastPage;
    }

    public boolean isHasPreviousPage() {
        return hasPreviousPage;
    }

    public void setHasPreviousPage(boolean hasPreviousPage) {
        this.hasPreviousPage = hasPreviousPage;
    }

    public boolean isHasNextPage() {
        return hasNextPage;
    }

    public void setHasNextPage(boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PageInfo<?> pageInfo = (PageInfo<?>) o;
        return pageNum == pageInfo.pageNum &&
                pageSize == pageInfo.pageSize &&
                size == pageInfo.size &&
                total == pageInfo.total &&
                pages == pageInfo.pages &&
                isFirstPage == pageInfo.isFirstPage &&
                isLastPage == pageInfo.isLastPage &&
                hasPreviousPage == pageInfo.hasPreviousPage &&
                hasNextPage == pageInfo.hasNextPage &&
                Objects.equals(list, pageInfo.list);
    }

    @Override
    public int hashCode() {
        return Objects.hash(pageNum, pageSize, size, total, pages, list, isFirstPage, isLastPage, hasPreviousPage, hasNextPage);
    }

    @Override
    public String toString() {
        return "PageInfo{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", size=" + size +
                ", total=" + total +
                ", pages=" + pages +
                ", list=" + list +
                ", isFirstPage=" + isFirstPage +
                ", isLastPage=" + isLastPage +
                ", hasPreviousPage=" + hasPreviousPage +
                ", hasNextPage=" + hasNextPage +
                '}';
    }
}
